package com.tosit.bmx.controller.admin;

import com.tosit.bmx.common.json.JSONModel;
import com.tosit.bmx.common.json.JSONUtil;
import com.tosit.bmx.domian.Online;
import com.tosit.bmx.service.admin.WebManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 官网管理类
 *
 * @author tsl
 * @create 2018-04-26 17:15
 **/
@Controller
@RequestMapping()
public class OnlineController {
    @Autowired
    WebManagerService webManagerService;


    /**
     * 获取所有官网管理
     *
     * @param
     * @return
     * @author tsl
     * @date 2018/4/26 17:24
     */
    @RequestMapping(value = "/online", method = RequestMethod.GET)
    public void gainOnlineAll(HttpServletResponse response) {
        List<Online> result = webManagerService.gainOnlineAll();
        if (result != null) {
            JSONModel.put("data", result);
        } else {
            JSONModel.put("status", "fail");
        }
        JSONUtil.printJsonModel(response);
    }

    /**
     * 添加官网管理
     *
     * @param
     * @return
     * @author tsl
     * @date 2018/4/26 17:24
     */
    @RequestMapping(value = "/online", method = RequestMethod.POST)
    public void addOnline(Online online,HttpServletResponse response) {
        Integer result = webManagerService.addOnline(online);
        if (result != null) {
            JSONModel.put("status", "success");
        } else {
            JSONModel.put("status", "fail");
        }
        JSONUtil.printJsonModel(response);
    }


    /**
     * 删除一个或多个官网内容
     *
     * @param ids
     * @return
     * @author tsl
     * @date 2018/4/26 17:24
     */
    @RequestMapping(value = "/online", method = RequestMethod.DELETE)
    public void addOnline(@RequestBody List<Integer> ids, HttpServletResponse response) {
        Integer result = webManagerService.removeOnline(ids);
        if (result != null) {
            JSONModel.put("status", "success");
        } else {
            JSONModel.put("status", "fail");
        }
        JSONUtil.printJsonModel(response);
    }

    /**
     * 更新网站展示信息
     *
     * @param
     * @return
     * @author tsl
     * @date 2018/4/26 17:24
     */
    @RequestMapping(value = "/online", method = RequestMethod.PUT)
    public void modifyOnline(Online online,HttpServletResponse response) {
        Integer result = null;
        result= webManagerService.modifyOnline(online);
        if (result != null) {
            JSONModel.put("status", "success");
        } else {
            JSONModel.put("status", "fail");
        }
        JSONUtil.printJsonModel(response);
    }
}
